package com.guoxin.part2.chapter10;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author guoxin
 * @date 2019/8/29
 */
public class MyClassLoaderTest {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
        MyClassLoader classLoader = new MyClassLoader();
        Class<?> aClass = classLoader.loadClass("com.guoxin.part2.chapter10.HelloWorld");
        System.out.println(aClass.getClassLoader());
        Object helloWorld = aClass.newInstance();
        System.out.println(helloWorld);
        Method welcome = aClass.getMethod("welcome");
        String result = (String) welcome.invoke(helloWorld);
        System.out.println("Result:" + result);

//        ClassLoader extClassLoader = MyClassLoaderTest.class.getClassLoader().getParent();
//        MyClassLoader classLoader = new MyClassLoader("E:\\classloader1",extClassLoader);
//        Class<?> aClass = classLoader.loadClass("com.guoxin.part2.chapter10.HelloWorld");
//        System.out.println(aClass);
//        System.out.println(aClass.getClassLoader());
    }
}
